const dgram = require("dgram");
module.exports = {
  sendVoteInfo: function (address_list, domain, con_address, port) {
    var sender = dgram.createSocket("udp4");
    console.log("发起方将投票信息传递给各个账户", address_list);
    for (var index in address_list) {
      var address = address_list[index];
      var msg = { domain: domain, contract: con_address };
      if (index === address_list.length - 1) {
        sender.send(JSON.stringify(msg), port, address, (err) => {
          console.log(err);
          sender.close();
        });
      } else {
        sender.send(JSON.stringify(msg), port, address);
      }
    }
  },
  sendWitnessInfo: function (con_address, abi, address, port) {
    var sender = dgram.createSocket("udp4");
    console.log("将监控信息传递给负载节点");
    var msg = { con_address: con_address, abi: abi };
    sender.send(JSON.stringify(msg), port, address, (err) => {
      console.log(err);
      sender.close();
    });
  },
};

